package reflection;

import org.junit.Test;

/**
 * @author DuJiabao
 * @create 2021-01-12 22:28
 * 静态代理
 */
public class StaticProxyTest {
    @Test
    public void test() {
        NikeClothFactory nikeClothFactory = new NikeClothFactory();
        ProxyClothFactory proxyClothFactory = new ProxyClothFactory(nikeClothFactory);
        proxyClothFactory.produceCloth();
    }
}

/**
 * 接口,代理类和被代理类都需要实现接口
 */
interface ClothFactory {
    void produceCloth();
}

class ProxyClothFactory implements ClothFactory {
    private ClothFactory factory;

    public ProxyClothFactory(ClothFactory factory) {
        this.factory = factory;
    }

    @Override
    public void produceCloth() {
        System.out.println("代理类开始的一些操作");
        factory.produceCloth();
        System.out.println("代理类后面的一些操作");
    }
}

class NikeClothFactory implements ClothFactory {
    @Override
    public void produceCloth() {
        System.out.println("nike 生产衣服");
    }
}


